<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>管理员系统</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/iCheck/square/blue.css">
</head>

<body class="hold-transition skin-purple sidebar-mini">

<div class="wrapper">

    <%@include file="header.jsp"%>

    <%@include file="aside.jsp"%>

    <div class="content-wrapper">
        <section class="content-header">
            <h1>
                商品管理
                <small>商品列表</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="${pageContext.request.contextPath}/pages/manage/main.jsp"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li><a href="#">商品管理</a></li>
                <li class="active">商品列表</li>
            </ol>
        </section>

        <section class="content">

            <div class="box box-primary">
                    <div class="box-header with-border">
                        <select name="qryfidType" id="qryfidType" style="width: 20%;height:40px;">
                            <option value="">-请选择父类-</option>
                            <c:forEach var="flist" items="${flist}">
                                <option value="${flist.cate_id}" <c:if test="${param.qryfidType==flist.cate_id}">selected</c:if>>${flist.cate_name}</option>
                            </c:forEach>
                        </select>
                        <select name="qrycidType" id="qrycidType" style="width: 20%;height:40px;margin-left: 20px;">
                            <option value="">-请选择子类-</option>
                            <c:forEach var="clist" items="${clist}">
                                <option value="${clist.cate_id}" <c:if test="${param.qrycidType==clist.cate_id}">selected</c:if>>${clist.cate_name}</option>
                            </c:forEach>
                        </select>
                        <select name="qrystatus" id="qrystatus"  style="width: 20%;margin-left: 20px;height:40px;">
                            <option value="">-请选择商品状态-</option>
                            <option value="1" <c:if test="${param.qrystatus=='1'}">selected</c:if>>上架</option>
                            <option value="0" <c:if test="${param.qrystatus=='0'}">selected</c:if>>下架</option>
                        </select>
                        <input type="text" id="qrysearch" name="qrysearch" style="width: 20%;margin-left: 20px;height:40px;"  placeholder="关键字" value="${param.qrysearch}">
                        <button type="submit" id="search" style="width:10%;height: 45px;margin-top: 10px;margin-left: 20px;height:40px;">查询</button>

                    </div>
                </form>

                <div class="box-body">

                    <div class="table-box">

                        <div class="pull-left">
                            <div class="form-group form-inline">
                                <div class="btn-group">
                                    <button type="button" class="btn btn-default" onclick="location.href='${pageContext.request.contextPath}/product/productadd'">
                                        <i class="fa fa-file-o"></i> 添加</button>
                                    <button type="button" class="btn btn-default" onclick="shangjia()"><i class="fa fa-check"></i> 上架</button>
                                    <button type="button" class="btn btn-default" onclick="xiajia()"><i class="fa fa-ban"></i> 下架</button>

                                </div>
                            </div>
                        </div>
                        <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
                            <thead>
                            <tr>
                                <th class="" style="padding-right:0px;">
                                    <input id="selall" type="checkbox" class="icheckbox_square-blue">
                                </th>
                                <th class="sorting">ID</th>
                                <th class="sorting">商品名称</th>
                                <th class="sorting">商品价格</th>
                                <th class="sorting">商品库存</th>
                                <th class="sorting">商品图片</th>
                                <th class="sorting">所属子分类</th>
                                <th class="sorting">所属父分类</th>
                                <th class="sorting">商品状态</th>
                                <th class="text-center">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:if test="${not empty pageInfo.list }">
                                <c:forEach items="${pageInfo.list}" var="Product">
                                    <tr style="height: 40px;">
                                        <td><input name="ids" type="checkbox" class="checkb" value="${Product.product_id}"></td>
                                        <td>${Product.product_id}</td>
                                        <td>${Product.product_name}</td>
                                        <td>${Product.product_price}</td>
                                        <td>${Product.product_stock}</td>
                                        <td><img src="/product/${Product.product_image}" style="width: 50px;height: 40px;"/></td>
                                        <td>${Product.product_cid_name}</td>
                                        <td>${Product.product_fid_name}</td>
                                        <td>
                                            <c:if test="${Product.product_status==1}">
                                                上架
                                            </c:if>
                                            <c:if test="${Product.product_status==0}">
                                                下架
                                            </c:if>
                                        </td>
                                        <td class="text-center">
                                            <button type="button" class="btn bg-olive btn-xs" onclick="location.href='${pageContext.request.contextPath}/product/findproductById?product_id=${Product.product_id}'">编辑</button>
                                        </td>
                                    </tr>
                                </c:forEach>
                            </c:if>
                            </tbody>
                        </table>
                        <c:if test="${empty pageInfo.list }">
                            <div class="alert alert-warning text-center my-5 py-5 col-12  col-md-12 offset-md-6" role="alert">
                                没有任何符合条件的产品信息
                            </div>
                        </c:if>


                    </div>


                </div>
                <div class="box-footer">
                    <div class="pull-left">
                        <div class="form-group form-inline">
                            总共${pageInfo.pages}页，共${pageInfo.total}条数据。 每页
                            <select class="form-control" id="changePageSize" name="choose" onchange="changePageSize()">
                                <option>${pageInfo.pageSize}</option>
                                <c:forEach begin="1" end="10" var="pageSize">
                                    <option>${pageSize}</option>
                                </c:forEach>
                            </select> 条
                        </div>
                    </div>

                    <div class="box-tools pull-right">
                        <ul class="pagination">
                            <li>
                                <a href="${pageContext.request.contextPath}/product/findProduct?page=1&size=${pageInfo.pageSize}&qryfidType=${param.qryfidType}&qrycidType=${param.qrycidType}&qrystatus=${param.qrystatus}&qrysearch=${param.qrysearch}" aria-label="Previous" >首页</a>
                            </li>
                            <li><a href="${pageContext.request.contextPath}/product/findProduct?page=${pageInfo.pageNum-1}&size=${pageInfo.pageSize}&qryfidType=${param.qryfidType}&qrycidType=${param.qrycidType}&qrystatus=${param.qrystatus}&qrysearch=${param.qrysearch}">上一页</a></li>
                            <c:forEach begin="1" end="${pageInfo.pages}" var="pageNum">
                                <li><a href="${pageContext.request.contextPath}/product/findProduct?page=${pageNum}&size=${pageInfo.pageSize}&qryfidType=${param.qryfidType}&qrycidType=${param.qrycidType}&qrystatus=${param.qrystatus}&qrysearch=${param.qrysearch}" >${pageNum}</a></li>
                            </c:forEach>

                            <li><a href="${pageContext.request.contextPath}/product/findProduct?page=${pageInfo.pageNum+1}&size=${pageInfo.pageSize}&qryfidType=${param.qryfidType}&qrycidType=${param.qrycidType}&qrystatus=${param.qrystatus}&qrysearch=${param.qrysearch}" >下一页</a></li>
                            <li>
                                <a href="${pageContext.request.contextPath}/product/findProduct?page=${pageInfo.pages}&size=${pageInfo.pageSize}&qryfidType=${param.qryfidType}&qrycidType=${param.qrycidType}&qrystatus=${param.qrystatus}&qrysearch=${param.qrysearch}"  aria-label="Next">尾页</a>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>
    </div>

<script src="${pageContext.request.contextPath}/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/jQueryUI/jquery-ui.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/iCheck/icheck.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/adminLTE/js/app.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/select2/select2.full.min.js"></script>
<script>

    function changePageSize(){
        var pagesize = $("#changePageSize").val();
        location.href="${pageContext.request.contextPath}/product/findProduct?page=1&qryfidType=${param.qryfidType}&qrycidType=${param.qrycidType}&qrystatus=${param.qrystatus}&qrysearch=${param.qrysearch}&size="+pagesize;
    }
    $('#search').click(function () {
        var qryfidType = $("#qryfidType").val();
        var qrycidType = $("#qrycidType").val();
        var qrystatus = $("#qrystatus").val();
        var qrysearch = $("#qrysearch").val();
        location.href="${pageContext.request.contextPath}/product/findProduct?qryfidType="+qryfidType+"&qrycidType="+qrycidType+
        "&qrystatus="+qrystatus+"&qrysearch="+qrysearch;
    });

    function choose(){
        var id = $("#choose").val();
    }
    $(document).ready(function() {
        // 选择框
        $(".select2").select2();

        // WYSIHTML5编辑器
        $(".textarea").wysihtml5({
            locale: 'zh-CN'
        });
    });

    function shangjia() {
        var result = "";
        var count = 0;
        $(".checkb").each(function () {
            if ($(this).is(':checked')) {
                result += $(this).val() + ",";
                count++;
            } else {
            }
        });
        if(count==0){
            alert('请选择用户');
            return;
        }
        else if (!confirm("确定上架这" + count + "个商品?")) {
            return;
        }
        location.href = "${pageContext.request.contextPath}/product/shangjia?tag=" + result;
    }

    function xiajia() {
        var result = "";
        var count = 0;
        $(".checkb").each(function () {
            if ($(this).is(':checked')) {
                result += $(this).val() + ",";
                count++;
            } else {
            }
        });
        if(count==0){
            alert('请选择商品');
            return;
        } else if (!confirm("确定下架这" + count + "件商品?")) {
            return;
        }
        location.href = "${pageContext.request.contextPath}/product/xiajia?tag=" + result;
    }


    // 设置激活菜单
    function setSidebarActive(tagUri) {
        var liObj = $("#" + tagUri);
        if (liObj.length > 0) {
            liObj.parent().parent().addClass("active");
            liObj.addClass("active");
        }
    }


    $(document).ready(function() {

        // 激活导航位置
        setSidebarActive("product-manage");

        // 列表按钮
        $("#dataList td input[type='checkbox']").iCheck({
            checkboxClass: 'icheckbox_square-blue',
            increaseArea: '20%'
        });
        // 全选操作
        $("#selall").click(function() {
            var clicks = $(this).is(':checked');
            if (!clicks) {
                $("#dataList td input[type='checkbox']").iCheck("uncheck");
            } else {
                $("#dataList td input[type='checkbox']").iCheck("check");
            }
            $(this).data("clicks", !clicks);
        });
    });
</script>
</body>

</html>